// Replication file for "How the Objective Approach Fails in Democracies" in PS: Political Science & Politics
// Prepared by Michael K. Miller (mkm2@gwu.edu), October 2023



use backsliding_replication.dta


// Figure 1

sort ccode year
gen fvpolyarchy = F.vdem_polyarchy
by hdecade bmr4, sort: egen change1_hd_vpolyarchy = mean(fvpolyarchy - vdem_polyarchy)
sort ccode year
gen ffhs = F.fh_s
by hdecade bmr4, sort: egen change1_hd_fhs = mean(ffhs - fh_s)
sort ccode year
gen fpolity2s = F.polity2_s
by hdecade bmr4, sort: egen change1_hd_polity2s = mean(fpolity2s - polity2_s)

tw line change1_hd_vpolyarchy hdecade if bmr4==1 & year >= 1981 || line change1_hd_fhs hdecade if bmr4==1 & year >= 1981 || line change1_hd_polity2s hdecade if bmr4==1 & year >= 1981 || sc change1_hd_vpolyarchy hdecade if bmr4==1 & year >= 1981 || sc change1_hd_fhs hdecade if bmr4==1 & year >= 1981 || sc change1_hd_polity2s hdecade if bmr4==1 & year >= 1981
tw line change1_hd_vpolyarchy hdecade if bmr4==0 & year >= 2001 || line change1_hd_fhs hdecade if bmr4==0 & year >= 2001 || line change1_hd_polity2s hdecade if bmr4==0 & year >= 2001 || sc change1_hd_vpolyarchy hdecade if bmr4==0 & year >= 2001 || sc change1_hd_fhs hdecade if bmr4==0 & year >= 2001 || sc change1_hd_polity2s hdecade if bmr4==0 & year >= 2001


// Figure 2 (created with Heat Map tool at insights.datylon.com)

pwcorr oindex vdem_polyarchy fh_s polity2_s uds if bmr4==1


// Figure 3 (created with Heat Map tool at insights.datylon.com)

pwcorr oindex vdem_polyarchy uds xx2_loggdp vdem_educ bmr4_age human_fariss c_dem_wt if bmr4==1


// Table 1

global main "year xx2_loggdp bmr4_age"
global cond "if bmr4==1"
eststo clear
eststo: quietly probit fbmr4_rev oindex vdem_polyarchy $cond, r
eststo: quietly probit fbmr4_rev oindex vdem_polyarchy $main $cond, r
eststo: quietly probit fxx_irreg oindex vdem_polyarchy $cond, r
eststo: quietly probit fxx_irreg oindex vdem_polyarchy $main $cond, r
eststo: quietly probit fxx_coup oindex vdem_polyarchy $cond, r
eststo: quietly probit fxx_coup oindex vdem_polyarchy $main $cond, r
esttab, b(3) pr2


// Figure 4

ssc install coefplot
set scheme s1color
probit nelda_monfraud oindex vdem_polyarchy if bmr4==1 & nelda_monitors==1 & nelec==1
margins, at(oindex = (0.36(0.01)1)) post
est store model1
probit nelda_monfraud oindex vdem_polyarchy if bmr4==1 & nelda_monitors==1 & nelec==1
margins, at(vdem_polyarchy = (0.36(0.01)0.92)) post
est store model2
coefplot model1 model2, at recast(line) ciopts(recast(rline) lpattern(dash))


// Figure 5

gen nturnparty = 1*(nelda_turnover==1)
replace nturnparty = . if nelda_turnover==.
by hdecade bmr4 nelec, sort: egen nturnparty_hd = mean(nturnparty)

gen nturnparty_clean = nturnparty
replace nturnparty_clean = 0 if nelda_incturnreason > 1 & nelda_incturnreason !=.
replace nturnparty_clean = 0 if nelda_protviolence==1 | nelda_violence==1 | nelda_protfraud==1 
by hdecade bmr4 nelec, sort: egen nturnparty_clean_hd = mean(nturnparty_clean)

tw sc nturnparty_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991 || line nturnparty_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991 || sc nturnparty_clean_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991 || line nturnparty_clean_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991


gen neturn = 1*(nelda_incturnover==1)
replace neturn = . if nelda_incturnover == .
gen neturn_clean = neturn
replace neturn_clean = 0 if nelda_incturnreason > 1 & nelda_incturnreason !=.
replace neturn_clean = 0 if nelda_protviolence==1 | nelda_protfraud==1 | nelda_violence==1
by hdecade bmr4 neelec2, sort: egen neturn_clean_hd = mean(neturn_clean)

gen nelda_oppgain_clean = nelda_oppgain
replace nelda_oppgain_clean = 0 if nelda_incturnreason > 1 & nelda_incturnreason < 5
replace nelda_oppgain_clean = 0 if nelda_protviolence==1 | nelda_violence==1 | nelda_protfraud==1 
by hdecade bmr4 nelec, sort: egen nopp_clean_hd = mean(nelda_oppgain_clean)

tw line neturn_clean_hd hdecade if bmr4==1 & neelec2==1 & hdecade >= 1991 || sc neturn_clean_hd hdecade if bmr4==1 & neelec2==1 & hdecade >= 1991 || line nopp_clean_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991 || sc nopp_clean_hd hdecade if bmr4==1 & nelec==1 & hdecade >= 1991









// Coding Notes

//gen hdecade = 5*floor((year-1)/5)+1
//replace hdecade = 2016 if year==2021

//gen nelec = 1*(nelda_legelection==1 | nelda_execelection==1)
//replace nelec = . if nelda_legelection==. & nelda_execelection == .
//gen neelec2 = 1*(nelec==1 & nelda_incrun==1)
//replace neelec2 = . if nelec==. | nelda_incrun==.

//gen fbmr4 = F.bmr4
//gen fbmr4_rev = 1 - fbmr4
//gen fxx_coup = F.xx_coup
//gen fxx_irreg = F.xx_irreg

// Weighted WVS (from WVS common file) 
//gen ccode = COW_NUM
//gen year = S020
//gen weight = S017
//gen satis = E110
//replace satis = . if E110 <= 0
//replace satis = ((4 - satis)/3)*9 + 1
//by ccode year, sort: egen c_satis_wt = wtmean(satis), weight(weight)
//gen isdem = E236
//replace isdem = . if E236 <= 0
//by ccode year, sort: egen c_isdem_wt = wtmean(isdem), weight(weight)
//gen c_dem_wt = c_isdem_wt
//replace c_dem_wt = c_satis_wt if c_isdem_wt==.

// NELDA (corresponding variables)
//nelda_monfraud <-> nelda47
//nelda_monitors <-> nelda45
//nelda_turnover <-> nelda24
//nelda_protviolence <-> nelda31
//nelda_violence <-> nelda33
//nelda_protfraud <-> nelda30
//nelda_incturnover <-> nelda39
//nelda_oppgain <-> nelda27
//nelda_legelection  <-> type = "Legislative/Parliamentary"
//nelda_execelection <-> type = "Executive"
//nelda_incrun <-> nelda21
//nelda_incturnreason <-> 0 if no incturnover; 1 if nelda40 = "yes"; 2 if nelda41 = "yes"; 3 if nelda40 & nelda41 = "yes"; 4 if nelda42 = "yes"; 5 if nelda40-42 all not "yes"





